import os, time
from multiprocessing import Pool


def compute(i):
    time.sleep(1)
    return i * i


def pool_map():
    print("cpu count: ", os.cpu_count())
    with Pool(processes=4) as pool:
        results = pool.map(compute, range(10))
        print(results)
        
        
def pool_map_async():
    print("cpu count: ", os.cpu_count())
    with Pool(processes=4) as pool:
        pool.map_async(compute, range(10), callback=collect_result)
        pool.close()
        pool.join()
        
        
def collect_result(result):
    print("result: ", result)


if __name__ == '__main__':
    pool_map()
    pool_map_async()